function requestverify({ requestconfig, requestrules }) {
  const result = {
    code: 0,
    msg: '校验通过'
  }
  if (requestrules.method && requestconfig.httpMethod != requestrules.method) {
    return {
      code: 1000,
      msg: '请求方法错误'
    }
  }
  if (requestrules.referer && Array.isArray(requestrules.referer)) {
    if (!requestconfig.headers.referer || !requestrules.referer.includes(requestconfig.headers.referer)) {
      return {
        code: 1001,
        msg: '请求来源不合法'
      }
    }
  }
  if (requestrules.body && requestrules.body.length > 0) {
    let body
    if (requestconfig.body) {
      body = requestconfig.body
    } else {
      body = {}
    }
    for (const rule of requestrules.body) {
      const { name, type, mustneed, validvalues } = rule
      if (mustneed && body[name] === undefined) {
        return {
          code: 1002,
          msg: '请求参数错误'
        }
      }
      if (body[name] !== undefined) {
        switch (type) {
          case 'string':
            if (typeof body[name] != 'string') {
              return {
                code: 1003,
                msg: '请求参数错误'
              }
            }
            break
          case 'boolean':
            if (typeof body[name] != 'boolean') {
              return {
                code: 1003,
                msg: '请求参数错误'
              }
            }
            break
          case 'number':
            if (typeof body[name] != 'number' || !Number.isInteger(body[name]) || body[name] < 0) {
              return {
                code: 1003,
                msg: '请求参数错误'
              }
            }
            break
          case 'array':
            if (!Array.isArray(body[name])) {
              return {
                code: 1003,
                msg: '请求参数错误'
              }
            }
            break
          default:
            throw '不支持校验该类型'
        }
        if (validvalues && !validvalues.includes(body[name])) {
          return {
            code: 1004,
            msg: '请求参数不合法'
          }
        }
      }
    }
  }
  return result
}
export default requestverify